import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ActivityView from '@/views/ActivityView'
import CameraView from '@/views/CameraView'
import LoginView from '@/views/LoginView'
import NotFound from '@/views/NotFound'
import RegisterView from '@/views/RegisterView'
import OrderView from '@/views/OrderView'
import MySpace from '@/views/MySpace'
import MyInfo from '@/views/MyInfo'
import WorkInfo from '@/views/WorkInfo'
import ActivityInfo from '@/views/ActivityInfo'
import CreateWork from '@/views/CreateWork'
import MyWork from '@/views/MyWork'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index',
    component: HomeView
  },
  {
    path: '/index',
    name: 'index',
    component: HomeView
  },
  {
    path: '/camera',
    name: 'camera',
    component: CameraView
  },
  {
    path: '/activity',
    name: 'activity',
    component: ActivityView
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/register',
    name: 'register',
    component: RegisterView
  },
  {
    path: '/info',
    name: 'info',
    component: MyInfo
  },
  {
    path: '/404',
    name: '404',
    component: NotFound
  },
  {
    path: '/order',
    name: 'order',
    component: OrderView
  },
  {
    path: '/space',
    name: 'space',
    component: MySpace
  },
  {
    path: '/myWork',
    name: 'myWork',
    component: MyWork
  },
  {
    path: '/create',
    name: 'create',
    component: CreateWork
  },
  {
    path: '/workInfo',
    name: 'workInfo',
    component: WorkInfo
  },
  {
    path: '/activityInfo',
    name: 'activityInfo',
    component: ActivityInfo
  },
  {
    path: "/:catchAll(.*)",
    redirect: "/404"
  }

]

// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location){
return originalPush.call(this , location).catch(err=>err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location){
return originalReplace.call(this , location).catch(err=>err)
}


const router = new VueRouter({
  routes,
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})

export default router
